package uk.ac.strath.cis.religionsearch.controller;

import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import uk.ac.strath.cis.religionsearch.view.SearchWindow;
import uk.ac.strath.cis.religionsearch.model.Model;

public class Controller {
	
	private Model model;
	private SearchWindow gui;
	
	public Controller(Model _model){
		model = _model;
		gui = new SearchWindow(this);

		SwingUtilities.invokeLater(new Runnable() {	
			public void run() {
				try{
					UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
				}
				catch (Exception e) {
					e.printStackTrace();
				}
				gui.init();
				model.addObserver(gui);
			}
		});	
	}
	
	public void searchPressed(String _query){
		try{
			model.search(_query, true, true, true, false);
		} catch(Exception e) {
			System.err.println("awww shiiittt : " + e);
		}
	}
	
	public void applyBookFilter(int i){
		try {
			model.filterResultsBook(i);
		} catch (Exception e) {
		}
	}
	
	public String getPreview(int index){
		
		
		try {
			return model.getDocumentAtIndex(index);
		} catch (Exception e) {
		} return "awww shit";
	}
	
	public String getIndexLoc(){
		return model.getIndexSrcFilesLoc();
	}
	
	public void setIndexLoc(String loc){
		model.setIndexSrcFilesLoc(loc);
	}

	public void setIndexDest(String indexDest) {
		model.setIndexDest(indexDest);
		
	}

	public void startIndexing() {
		model.startIndexing();
		
	}
	
}
